<#import "/jblog-admin.html" as jblogAdmin/>
<table class="am-table am-table-hover">
    <thead>
        <tr>
            <th width="50%" id="id-page-title">${pageTitle}</th>
            <th width="10%">状态</th>
            <th width="10%">评论数</th>
            <th width="10%">点击量</th>
            <th width="10%">操作</th>
        </tr>
    </thead>
    <tbody>
<#list pagerArticles.data as article>
		<tr>
      <td><a href="${rc.contextPath}/article/show/<#if article.urlName ??>${article.urlName}<#else>${article.articleId}</#if>" target="_blank">${article.title} (${article.createDate})</a></td>
      <td><#if article.state = 0><i class="am-icon-hourglass-start" /><#elseif article.state = 1><i class="am-icon-share-alt" /><#elseif article.state = 2><i class="am-icon-trash" /></#if></td>
      <td><span class="am-badge am-round am-badge-secondary article-comments-count" data=${article.articleId}>0</span></td>
      <td><span class="am-badge am-round am-badge-success">${article.rate}</span></td>
      <td class="admin-article-controls" data="${article.articleId}">
        <span class="am-badge am-radius am-badge-primary">
          <i class="am-icon-<#if article.state = 2>share-square-o<#else>edit</#if> am-icon-md"></i>
				</span>
				<span class="am-badge am-radius am-badge-danger">
					<i class="am-icon-trash am-icon-md"></i>
				</span>
      </td>
    </tr>
</#list>
    </tbody>
</table>
<#if (pagerArticles.totalPages > 1) >
<@jblogAdmin.amPagination urls = pagerArticles.urls current = pagerArticles.currentPage/>
</#if>

<script type="text/javascript">
	$(function(){
    var commentIds = "";
    $(".article-comments-count").each(function(){
      commentIds += ($(this).attr("data") + ",");
    });
    commentIds = commentIds.slice(0, -1);

    var url = "http://api.duoshuo.com/threads/counts.jsonp?short_name=${duoshuoId}&threads=" + commentIds +"&callback=?";

    $.getJSON(url, function(data){
      $(".article-comments-count").each(function(){
        $(this).html(data.response[$(this).attr("data")].comments);
      });
    });

    var url = "";

		$(".admin-article-controls .am-badge-danger").bind("click",function(){
			var articleid = $(this).parents(".admin-article-controls").attr("data");
      new fn_alert("确定<#if trashbox ??>永久</#if>删除这条记录？ID：" + articleid).show(function(me){
        var url = "${rc.contextPath}/article/admin/" + articleid + "/delete<#if trashbox ??>-forever</#if>";
        dimmer(true);
        $.ajax({
          "url" : url,
          data  : {"${_csrf.parameterName}":"${_csrf.token}"},
          type  : "post",
          success : function(data){
            $("#id-main-frame").html(data);
            dimmer(false);
          },
          error : function(){alert("抱歉，来宾帐户无法对系统做出修改！");dimmer(false);},
          dataType : "html"
        });
      });
    });

    $(".admin-article-controls .am-icon-edit").bind("click",function(){
      var articleid = $(this).parents(".admin-article-controls").attr("data");
      $.get("${rc.contextPath}/article/admin/" + articleid + "/update", function(data){
        $("#id-main-frame").html(data);
      });
    });

    $(".admin-article-controls .am-icon-share-square-o").bind("click",function(){
      var articleid = $(this).parents(".admin-article-controls").attr("data");
      new fn_alert("确定恢复这条记录？ID：" + articleid).show(function(me){
        var url = "${rc.contextPath}/article/admin/" + articleid + "/recovery";
        dimmer(true);
        $.ajax({
          "url" : url,
          type  : "post",
          data  : {"${_csrf.parameterName}":"${_csrf.token}"},
          success : function(data){
            
            $("#id-main-frame").html(data);
            dimmer(false);
          },
          error : function(){alert("抱歉，来宾帐户无法对系统做出修改！");dimmer(false);},
          dataType : "html"
        });
      });
    });
	});
</script>